package com.itheima.demo;

import com.itheima.domain.Items;
import com.itheima.domain.Orders;
import com.itheima.domain.User;
import com.itheima.mapper.OrdersMapper;
import com.itheima.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.util.List;

public class Demo1 {
    public static void main(String[] args) throws Exception {
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("sql.xml"));
        SqlSession session = factory.openSession();

        UserMapper mapper = session.getMapper(UserMapper.class);
        List<User> list = mapper.findAll();
        for (User user : list) {
            System.out.println("用户名称:"+user.getUsername());
            List<Orders> o = user.getOrdersList();
            for (Orders orders : o) {
                System.out.println("订单编号:"+orders.getNumber());
                List<Items> items = orders.getItemsList();
                for (Items item : items) {
                    System.out.println("商品名称:"+item.getName());
                }
            }

        }
        session.close();
    }
}
